package handler

import (
	"api/basic/config"
	"api/basic/proto/docker"
	"api/handler/request"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
	"log"
	"net/http"
)

func InstitutionsList(c *gin.Context) {
	r, err := config.Pb.InstitutionsList(c, &docker.InstitutionsListReq{})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("Greeting: %s", r)
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "机构展示成功",
		"data": r,
	})
}

func TeamsList(c *gin.Context) {
	var Temaslist request.TeamsListReq
	err := c.ShouldBind(&Temaslist)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "错误",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Pb.TeamsList(c, &docker.TeamsListReq{InstitutionId: Temaslist.InstitutionId})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("Greeting: %s", r)
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "团队展示成功",
		"data": r,
	})
}

func DockerList(c *gin.Context) {
	var dockerlist request.DockerListReq
	err := c.ShouldBind(&dockerlist)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "错误",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Pb.DockerList(c, &docker.DockerListReq{TeamId: dockerlist.TeamId})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("Greeting: %s", r)
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "医生展示成功",
		"data": r,
	})
}

func DockerOne(c *gin.Context) {
	var dockerone request.DockerOneReq
	err := c.ShouldBind(&dockerone)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "错误",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Pb.DockerOne(c, &docker.DockerOneReq{DockerId: dockerone.DockerId})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("Greeting: %s", r)
	newString := uuid.NewString()
	fmt.Println(newString)
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "医生详情展示成功",
		"data": r,
	})
}
